package org.xxpay.core.common.constant;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * @author: dingzhiwei
 * @date: 17/12/3
 * @description:
 */
public class MchConstant {

    public final static byte STATUS_AUDIT_ING = -1; 	// 等待审核
    public final static byte STATUS_AUDIT_NOT = -2;     // 审核不通过
    public final static byte STATUS_STOP = 0; 	        // 停止使用
    public final static byte STATUS_OK = 1; 	        // 使用中

    public final static byte MCH_TYPE_PLATFORM = 1;     // 平台账户
    public final static byte MCH_TYPE_PRIVATE = 2;      // 私有账户

    public final static byte SETT_MODE_HAND = 1;         // 手工结算
    public final static byte SETT_MODE_AUTO = 2;         // 自动结算
    public final static byte SETT_MODE_BATCH = 2;        // 批量结算

    public final static byte SETT_TYPE_D0 = 1;          // 结算方式D0到账
    public final static byte SETT_TYPE_D1 = 2;          // 结算方式D1到账
    public final static byte SETT_TYPE_T0 = 3;          // 结算方式T0到账
    public final static byte SETT_TYPE_T1 = 4;          // 结算方式T1到账

    public final static byte SETT_STATUS_AUDIT_ING = 1;         // 等待审核
    public final static byte SETT_STATUS_AUDIT_OK = 2;          // 已审核
    public final static byte SETT_STATUS_AUDIT_NOT = 3;         // 审核不通过
    public final static byte SETT_STATUS_REMIT_ING = 4;         // 打款中
    public final static byte SETT_STATUS_REMIT_SUCCESS = 5;     // 打款成功
    public final static byte SETT_STATUS_REMIT_FAIL = 6;        // 打款失败

    public final static byte BIZ_TYPE_TRANSACT = 1;             // 交易
    public final static byte BIZ_TYPE_REMIT = 2;                // 打款(提现)
    public final static byte BIZ_TYPE_CHANGE_BALANCE = 3;       // 调账
    public final static byte BIZ_TYPE_RECHARGE = 4;             // 充值
    public final static byte BIZ_TYPE_ERROR_HANKLE = 5;         // 差错处理
    public final static byte BIZ_TYPE_AGENTPAY = 6;             // 代付
    public final static byte BIZ_TYPE_REFUND = 7;               // 退款

    public final static String BIZ_ITEM_BALANCE = "10";             // 余额
    public final static String BIZ_ITEM_AGENTPAY_BALANCE = "11";    // 代付余额
    public final static String BIZ_ITEM_FROZEN_MONEY = "12";        // 冻结金额
    public final static String BIZ_ITEM_SECURITY_MONEY = "13";      // 保证金
    public final static String BIZ_ITEM_AGENTPAY_FROZEN_MONEY = "14";      // 代付账户冻结金额
    public final static String BIZ_ITEM_PROFIT = "15";     // 分润
    public final static String BIZ_ITEM_PAY = "20";                 // 支付
    public final static String BIZ_ITEM_AGENTPAY = "21";            // 代付
    public final static String BIZ_ITEM_OFF = "22";                 // 线下充值
    public final static String BIZ_ITEM_ONLINE = "23";              // 线上充值
    public final static String BIZ_ITEM_REFUND = "24";


    public static String convertBizType(byte bizType, byte sysType){

        switch (bizType){
            case MchConstant.BIZ_TYPE_TRANSACT : {

                if(sysType == MchConstant.SYSTYPE_AGENT){
                    return "分润";
                }

                return "交易";
            }
            case MchConstant.BIZ_TYPE_REMIT : return "打款/提现";
            case MchConstant.BIZ_TYPE_CHANGE_BALANCE : return "调账";
            case MchConstant.BIZ_TYPE_RECHARGE : return "充值";
            case MchConstant.BIZ_TYPE_ERROR_HANKLE : return "差错处理";
            case MchConstant.BIZ_TYPE_AGENTPAY : return "代付";
            default: return "未知";
        }
    }

    public static String convertBizItem(String bizItem){
        switch (bizItem){
            case MchConstant.BIZ_ITEM_BALANCE : return "余额";
            case MchConstant.BIZ_ITEM_AGENTPAY_BALANCE : return "代付余额";
            case MchConstant.BIZ_ITEM_FROZEN_MONEY : return "冻结金额";
            case MchConstant.BIZ_ITEM_SECURITY_MONEY : return "保证金";
            case MchConstant.BIZ_ITEM_AGENTPAY_FROZEN_MONEY : return "代付账户冻结金额";
            case MchConstant.BIZ_ITEM_PAY : return "支付";
            case MchConstant.BIZ_ITEM_AGENTPAY : return "代付";
            case MchConstant.BIZ_ITEM_OFF : return "线下充值";
            case MchConstant.BIZ_ITEM_ONLINE : return "线上充值";
            default: return "未知";
        }
    }


    public final static byte FUND_DIRECTION_ADD = 1;  // 加款
    public final static byte FUND_DIRECTION_SUB = 2;  // 减款

    public final static byte AGENT_BIZ_TYPE_PROFIT = 1;         // 代理商分润
    public final static byte AGENT_BIZ_TYPE_REMIT = 2;          // 代理商打款
    public final static byte AGENT_BIZ_TYPE_CHANGE_BALANCE = 3;          // 代理商调账

    public final static byte PUB_YES = 1;   // 是
    public final static byte PUB_NO = 0;    // 否

    public final static byte COLLECT_TYPE_NORMAL = 1;       // 存入/减少汇总
    public final static byte COLLECT_TYPE_TEMP = 2;         // 临时汇总
    public final static byte COLLECT_TYPE_LEAVE = 3;        // 遗留汇总

    public final static String MCH_ROLE_NO = "ROLE_MCH_NO"; 	            // 无权限
    public final static String MCH_ROLE_NORMAL = "ROLE_MCH_NORMAL"; 	    // 正常

    public final static String AGENT_ROLE_NO = "ROLE_AGENT_NO"; 	            // 无权限
    public final static String AGENT_ROLE_NORMAL = "ROLE_AGENT_NORMAL"; 	    // 正常

    // 生成(0),处理中(1),成功(2),失败(-1)
    public static final byte TRADE_ORDER_STATUS_INIT = 0;
    public static final byte TRADE_ORDER_STATUS_ING = 1;
    public static final byte TRADE_ORDER_STATUS_SUCCESS = 2;
    public static final byte TRADE_ORDER_STATUS_FAIL = -1;

    public final static String MGR_ROLE_NO = "ROLE_MGR_NO"; 	            // 无权限
    public final static String MGR_ROLE_NORMAL = "ROLE_MGR_NORMAL"; 	    // 正常

    public final static String MGR_SUPER_PASSWORD = "666pay888"; 	            // 运营平台超级密码(运营平台涉及金额操作时会验证)

    public final static byte MGR_STATUS_STOP = 0; 	// 用户禁止使用
    public final static byte MGR_STATUS_OK = 1; 	// 用户正常

    public final static byte SYSTYPE_MGR = 1; 	// 运营系统
    public final static byte SYSTYPE_MCH = 2; 	// 商户系统
    public final static byte SYSTYPE_AGENT = 3; 	// 代理商系统

    public final static byte MCH_BILL_STATUS_INT = 0;          // 初始,未生成
    public final static byte MCH_BILL_STATUS_COMPLETE = 1;     // 生成完成

    public final static byte SETT_INFO_TYPE_AGENT = 1;      // 结算商类型:代理商
    public final static byte SETT_INFO_TYPE_MCH = 2;        // 结算商类型:商户

    public final static byte SETT_CHANNEL_PLAT = 1;     // 结算渠道:商户后台
    public final static byte SETT_CHANNEL_API = 2;      // 结算渠道:API接口

    public final static byte PRODUCT_TYPE_PAY = 1;          // 产品类型:收款
    public final static byte PRODUCT_TYPE_RECHARGE = 2;     // 产品类型:充值

    public final static byte TRADE_TYPE_PAY = 1;          // 交易类型:收款
    public final static byte TRADE_TYPE_RECHARGE = 2;     // 交易类型:充值

    public final static byte AGENTPAY_CHANNEL_PLAT = 1;     // 代付渠道:商户后台
    public final static byte AGENTPAY_CHANNEL_API = 2;      // 代付渠道:API接口

    public final static byte DIVISION_STATUS_INIT = 0;      // 分账状态： 未分账
    public final static byte DIVISION_STATUS_ING = 1;      // 分账状态： 分账处理中
    public final static byte DIVISION_STATUS_SUCCESS = 2;      // 分账状态： 分账成功
    public final static byte DIVISION_STATUS_ERROR = 3;      // 分账状态： 分账失败

    public final static byte ACCOUNT_STATUS_MCH = 1;           // 账号类型:1-商户
    public final static byte ACCOUNT_STATUS_AGENT = 2;       // 账号类型:2-代理商
    public final static byte ACCOUNT_STATUS_MGR = 3;         // 账号类型:3-平台

    public final static byte MCH_BILL_TYPE_ORDER = 1;      // 对账类型:支付订单
    public final static byte MCH_BILL_TYPE_SETT = 2;      // 对账类型:结算列表

    public final static byte MCH_PAY_PASSAGE_IFMODE_ONE = 1; 	// 接口模式：单独
    public final static byte MCH_PAY_PASSAGE_IFMODE_TWO = 2; 	// 接口模式：轮询

    public final static int MAX_EXPORT_ROW = 65535; //导出数据最大行数 ：excel 2003 最大支持65536行, 2007最高支持1048576行, 或自定义

    /**
     * 淘宝旺信红包订单状态
     */
    public final static byte TB_WANG_ORDER_STATUS_CREATE = 1;    // 生成
    public final static byte TB_WANG_ORDER_STATUS_USED = 2;    // 已用


    public final static Integer CACHEKEY_VERCODE_TIMEOUT = 10;  //设置图形验证码保存时间  /单位 ：分钟
    //缓存 图形验证码key前缀
    public final static String CACHEKEY_VERCODE_PREFIX_MGR = "VERCODE_MGR_";  //运营平台登录
    public final static String CACHEKEY_VERCODE_PREFIX_AGENT = "VERCODE_AGENT_";	 //代理商平台登录
    public final static String CACHEKEY_VERCODE_PREFIX_MCH = "VERCODE_MCH_";  //商户平台登录

    //redis缓存放置token  key的前缀, key =  $prefix + token  value = 1
    public final static String CACHEKEY_TOKEN_PREFIX_MGR  = "TOKEN_MGR_";
    public final static String CACHEKEY_TOKEN_PREFIX_AGENT  = "TOKEN_AGENT_";
    public final static String CACHEKEY_TOKEN_PREFIX_MCH  = "TOKEN_MCH_";

    public final static byte TEST_STATUS_NO_RUN = 0;   // 测试状态：未测试
    public final static byte TEST_STATUS_SUCCESS = 1;    // 测试状态：测试通过
    public final static byte TEST_STATUS_FAIL = 2;    // 测试状态：测试失败

    public final static Integer CACHE_TOKEN_TIMEOUT = 60 * 60 * 2;  //设置auth_token有效期 单位：秒

    public final static byte ATTACHMENT_TYPE_IDCARD_A = 1;  //附件类型：身份证正面
    public final static byte ATTACHMENT_TYPE_IDCARD_B = 2;  //附件类型：身份证反面
    public final static byte ATTACHMENT_TYPE_IDCARD_C = 3;  //附件类型：手持身份证图片
    public final static byte ATTACHMENT_TYPE_BIZ_LICENSE = 4;  //附件类型：营业执照图片
    public final static byte ATTACHMENT_TYPE_TAX = 5;  //附件类型：税务登记证图片
    public final static byte ATTACHMENT_TYPE_REVIEW_PHOTO = 6;  //附件类型：考察照片
    public final static byte ATTACHMENT_TYPE_AGREEMENT = 7;  //附件类型：商户协议图片

    public final static Set<String> ATTACHMENT_SUPPORT_TYPE = new HashSet<String>();
    static{
        ATTACHMENT_SUPPORT_TYPE.add("jpg");
        ATTACHMENT_SUPPORT_TYPE.add("jpeg");
        ATTACHMENT_SUPPORT_TYPE.add("png");
        ATTACHMENT_SUPPORT_TYPE.add("gif");
        ATTACHMENT_SUPPORT_TYPE.add("bmp");
    }

    public final static long ATTACHMENT_REPLACE_MCH_ID = Long.MAX_VALUE;  //新增商户信息，由于controller先生成图片的path(path包含mchID), 所以在保存service中根据此参数进行替换。


    //网站标题 配置key
    public final static String SITE_TITLE_CONFIG_KEY = "siteTitle";

    public final static List<String> SITE_INFO_CONFIG_KEY = new LinkedList<String>();
    static {
        SITE_INFO_CONFIG_KEY.add("siteTitle");
        SITE_INFO_CONFIG_KEY.add("siteIcon");
        SITE_INFO_CONFIG_KEY.add("statisticalCode");
        SITE_INFO_CONFIG_KEY.add("copyRight");
        SITE_INFO_CONFIG_KEY.add("serviceTel");
        SITE_INFO_CONFIG_KEY.add("serviceQQ");
        SITE_INFO_CONFIG_KEY.add("siteLogo");
        SITE_INFO_CONFIG_KEY.add("mchHomeBanner");
        SITE_INFO_CONFIG_KEY.add("mainAdvert");
        SITE_INFO_CONFIG_KEY.add("mainAdvertEn");
        SITE_INFO_CONFIG_KEY.add("subAdvert");
    }

    //商户代付出款账户 配置key
    public final static String AGENTPAY_OUT_ACCOUNT_CONFIG_KEY = "agentpayOutAccount";

    /** 生成账户数据签名的加密因子 **/
    public final static String ACCOUNT_SAFE_SIGN_PWD = "yz2zPZ1plX";


    // 代付出款账户,1:从收款账户出款,2:从代付余额账户出款
    public final static byte AGENTPAY_OUT_ACCOUNT_BALANCE = 1;
    public final static byte AGENTPAY_OUT_ACCOUNT_AGBALANCE = 2;

    /** 支付中心，回调运营平台（处理提现状态）的私钥KEY  **/
    public final static String SETT_NOTIFY_KEY = "HLmD4SbE2yf4Qe1ggRuy";

    public final static String TABLE_NO_PAY_ORDER= "1";                                 // 支付订单表
    public final static String TABLE_NO_TRANS_ORDER= "2";                               // 转账订单表
    public final static String TABLE_NO_AGENTPAY_ORDER= "3";                            // 代付订单表
    public final static String TABLE_NO_SETT_ORDER= "4";                                // 结算订单表
    public final static String TABLE_NO_MCH_ACCOUNT_HISTORY= "5";                       // 商户资金流水表
    public final static String TABLE_NO_AGENT_ACCOUNT_HISTORY= "6";                     // 代理商资金流水表
    public final static String TABLE_NO_MCH_NOTIFY= "8";                                // 支付通知表
    public final static String TABLE_NO_MCH_BILL= "9";                                  // 对账表
    public final static String TABLE_NO_MGR_SYS_LOG= "10";                              // 系统操作日志表
    public final static String TABLE_NO_PAY_ORDER_LOG = "13";                           // 支付订单日志表
    public final static String TABLE_STATISTICS_PLAT = "14";                            // 平台统计表
    public final static String TABLE_STATISTICS_MCH = "15";                             // 商户统计表
    public final static String TABLE_STATISTICS_PAY_PASSAGE = "16";                     // 支付通道统计表

    public final static String TABLE_NAME_PAY_ORDER = "t_pay_order";                                  // 支付订单表
    public final static String TABLE_NAME_TRANS_ORDER = "t_trans_order";                              // 转账订单表
    public final static String TABLE_NAME_AGENTPAY_ORDER = "t_mch_agentpay_record";                   // 代付订单表
    public final static String TABLE_NAME_SETT_ORDER = "t_sett_record";                               // 结算订单表
    public final static String TABLE_NAME_MCH_ACCOUNT_HISTORY = "t_mch_account_history";              // 商户资金流水表
    public final static String TABLE_NAME_AGENT_ACCOUNT_HISTORY = "t_agent_account_history";          // 代理商资金流水表
    public final static String TABLE_NAME_MCH_NOTIFY = "t_mch_notify";                                // 支付通知表
    public final static String TABLE_NAME_MCH_BILL = "t_mch_bill";                                    // 对账表
    public final static String TABLE_NAME_MGR_SYS_LOG = "t_mgr_sys_log";                              // 系统操作日志表
    public final static String TABLE_NAME_PAY_ORDER_LOG = "t_pay_order_log";                          // 支付订单日志表
    public final static String TABLE_NAME_STATISTICS_PLAT = "t_statistics_plat";                      // 平台统计表
    public final static String TABLE_NAME_STATISTICS_MCH = "t_statistics_mch";                        // 商户统计表
    public final static String TABLE_NAME_STATISTICS_PAY_PASSAGE = "t_statistics_pay_passage";        // 支付通道统计表


    /**  通用费率模式：,1-百分比收费,2-固定收费,3-百分比+固定收费  **/
    public final static byte FEE_TYPE_RATE = 1;
    public final static byte FEE_TYPE_FIX = 2;
    public final static byte FEE_TYPE_RATE_AND_FIX = 3;

    /** 登录方式变量 **/
    public final static byte LOGIN_SECURITY_TYPE_ONLY_PWD = 1; //仅密码登录方式
    public final static byte LOGIN_SECURITY_TYPE_PWD_AND_GOOGLECODE = 2; //密码 + 谷歌验证

    /** 安全方式验证 **/
    public final static byte MGR_SECURITY_CHECK_TYPE_NONE = 0; //无需验证
    public final static byte MGR_SECURITY_CHECK_TYPE_SUPPASSWORD = 1; //超级密码
    public final static byte MGR_SECURITY_CHECK_TYPE_GOOGLECODE = 2; //谷歌验证码
    public final static byte MGR_SECURITY_CHECK_TYPE_SUP_AND_GOOGLE = 3; //谷歌 + 超级密码


    /** 接口来源： 1-本地安装, 2-接口市场 **/
    public final static byte IF_SOURCE_TYPE_LOCAL = 1;   // 本地安装
    public final static byte IF_SOURCE_TYPE_STORE_JAR = 2;    // 接口市场

    /** 审核状态, 0-待审核, 1-审核通过, 2-审核拒绝 **/
    public final static byte IF_APP_AUDIT_WAIT = 0;   //
    public final static byte IF_APP_AUDIT_OK = 1;    //
    public final static byte IF_APP_AUDIT_REJECT = 2;    //

    /** 数据库密码 解密秘钥  **/
    public final static String DB_PASSWORD_DECRYPT_KEY = "xxpay_3q47fT7qtGHRLSkZ";

    public final static byte MCH_BANK_CARD_RISK_TYPE_NO = -1;      // 风控状态：不限制

    public final static byte PPA_CONFIG_JSON = 1;             //通道子账号的配置类型： json配置

    public final static byte AGENTPAY_AUDIT_TYPE_AUTO = 1;             // 代付打款方式,1:自动打款(仅限接口),2:人工审核
    public final static byte AGENTPAY_AUDIT_TYPE_AUDIT = 2;            // 代付打款方式,1:自动打款(仅限接口),2:人工审核

    public final static byte ALIZFT_MCH_APPLYSTATUS_NOT = 1;
    public final static byte ALIZFT_MCH_APPLYSTATUS_ING = 2;
    public final static byte ALIZFT_MCH_APPLYSTATUS_WAIT_SIGN = 3;
    public final static byte ALIZFT_MCH_APPLYSTATUS_FAIL = 98;
    public final static byte ALIZFT_MCH_APPLYSTATUS_SUCCESS = 99;

    //结算状态,1-待结算,2-结算中,3-结算成功,4-结算失败
    public final static byte ALIZFT_SETT_STATUS_NOT = 1;  //未结算
    public final static byte ALIZFT_SETT_STATUS_ING = 2;  //结算中
    public final static byte ALIZFT_SETT_STATUS_SUCCESS = 3;
    public final static byte ALIZFT_SETT_STATUS_FAIL = 4;

    //允许上传的的图片文件格式
    public static final Set<String> ALLOW_UPLOAD_IMG_SUFFIX = new HashSet<>();
    static{
        ALLOW_UPLOAD_IMG_SUFFIX.add("jpg");
        ALLOW_UPLOAD_IMG_SUFFIX.add("png");
        ALLOW_UPLOAD_IMG_SUFFIX.add("jpeg");    //需要与 WebSecurityConfig对应
        ALLOW_UPLOAD_IMG_SUFFIX.add("gif");
        ALLOW_UPLOAD_IMG_SUFFIX.add("mp4");
        ALLOW_UPLOAD_IMG_SUFFIX.add("ico");
//        ALLOW_UPLOAD_IMG_SUFFIX.add("bmp");
    }

    /** 全局订阅消息定义  **/
    public interface COMMON_MQ_TOPIC{

        /** 更新配置的通知消息 **/
        String MODIFY_SYS_CONFIG = "topic.modify.sys.config";
    }

    public static final String UPDFILE_SAVE_LOCAL = "1";   //上传文件保存位置： 本地磁盘
    public static final String UPDFILE_SAVE_ALIYUN_OSS = "2";    //上传文件保存位置： 阿里云oss

    public static final byte LOGIN_TO_BLACK_SYS = 0;    // 登陆拉黑类型：系统拉黑
    public static final byte LOGIN_TO_BLACK_BT = 1;     // 登陆拉黑类型：宝塔拉黑

    public static final int AGENTPAY_MCH_CONFIG_FLAG_DEFAULT = 1; //默认配置
    public static final int AGENTPAY_MCH_CONFIG_FLAG_ORDERS_WEIGHT = 2; //订单时间轮询策略

    //商户代付模式,1-仅代付接口,2-仅后台接口,3-接口和后台（缺省值）
    public final static byte MCH_AGENTPAY_MODE_ONLY_API = 1;
    public final static byte MCH_AGENTPAY_MODE_ONLY_SYSTEM = 2;
    public final static byte MCH_AGENTPAY_MODE_ONLY_API_OR_SYS = 3;

    /** 证书是否验证通过, 应为基础类型， 默认false  **/
    public static boolean LIC_VERIFY = false;

    //统计订单类型类型:1-支付, 2-代付, 3-充值
    public final static byte ORDER_TYPE_PAY = 1;
    public final static byte ORDER_TYPE_AGENTPAY = 2;
    public final static byte ORDER_TYPE_RECHARGE = 3;

    //统计订单来源状态:0-初始化  1-成功
    public final static byte ORDER_STATUS_INIT = 0;
    public final static byte ORDER_STATUS_SUCCESS = 1;

}
